package com.ld.control.business.equipment.controller;


import com.ld.control.business.equipment.service.EquipmentMethodTmpService;
import com.ld.control.business.equipment.vo.req.EquipmentMethodTmpReqVo;
import com.ld.control.business.equipment.vo.req.MethodDebugReqVo;
import com.ld.control.business.equipment.vo.resp.EquipmentMethodTmpRespVo;
import com.ld.control.business.equipment.vo.resp.MethodDebugRespVo;
import com.ld.control.common.vo.GenerateListVo;
import com.ld.control.common.ResultResponse;
import com.ld.control.sysenum.ResultResponseEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 设备表 前端控制器
 * </p>
 *
 * @author wangfeng
 * @since 2024-04-17
 */
@Slf4j
@Tag(name = "设备方法模板相关接口")
@RestController
public class EquipmentMethodTmpController {

    @Autowired
    private EquipmentMethodTmpService equipmentMethodTmpService;


    @GetMapping("/api/centralControl/equipmentMethodTmp/getList")
    @Operation(summary = "设备方法模板列表")
    public ResultResponse<GenerateListVo<EquipmentMethodTmpRespVo>> getList(
            @RequestParam Long equipmentId,
            @Parameter(description = "只限于调试用，0否：1是")@RequestParam(required = false) Integer debugFlag
    ){
        List<EquipmentMethodTmpRespVo> equipmentMethodTmpRespVoList = equipmentMethodTmpService.getList(equipmentId, debugFlag);
        return ResultResponse.success(new GenerateListVo<>(equipmentMethodTmpRespVoList));
    }


    @PostMapping("/api/centralControl/equipmentMethodTmp/add")
    @Operation(summary = "新增设备方法模板")
    public ResultResponse<ResultResponseEnum> add(
            @RequestBody EquipmentMethodTmpReqVo reqVo
    ){
        equipmentMethodTmpService.add(reqVo);
        return ResultResponse.success();
    }

    @PostMapping("/api/centralControl/equipmentMethodTmp/update")
    @Operation(summary = "修改设备方法模板")
    public ResultResponse<ResultResponseEnum> update(
            @RequestBody EquipmentMethodTmpReqVo reqVo
    ){
        equipmentMethodTmpService.update(reqVo);
        return ResultResponse.success();
    }

    @PostMapping("/api/centralControl/equipmentMethodTmp/deleteById")
    @Operation(summary = "删除设备方法模板")
    public ResultResponse<ResultResponseEnum> deleteById(
            @RequestParam Long id
    ){
        equipmentMethodTmpService.deleteById(id);
        return ResultResponse.success();
    }

    @PostMapping("/api/centralControl/equipmentMethodTmp/sendDebugMethod")
    @Operation(summary = "发送方法调试")
    public ResultResponse<MethodDebugRespVo> sendDebugMethod(
            @RequestBody MethodDebugReqVo reqVo
    ){
        MethodDebugRespVo methodDebugRespVo = equipmentMethodTmpService.sendDebugMethod(reqVo);
        return ResultResponse.success(methodDebugRespVo);
    }

}

